<template>
  <div class="app-container">
    <div class="news-detail-container">
      <div class="news-header">
        <h1 class="news-title">{{ news.title }}</h1>
        <div class="news-meta">
          <span class="time">{{ parseTime(news.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
          <!-- <span class="author">{{ news.authorId }}</span> -->
        </div>
      </div>
      
      <div class="news-content" v-html="news.content"></div>
      
      <div class="news-footer">
        <el-button type="primary" @click="goBack">返回列表</el-button>
        <el-button type="info" @click="goHome">返回主页</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { getNews } from "@/api/news/news";

export default {
  name: 'NewsDetail',
  data() {
    return {
      news: {
        newsId: null,
        title: '',
        content: '',
        authorId: '',
        createTime: null
      }
    }
  },
  created() {
    this.getNewsDetail();
  },
  methods: {
    getNewsDetail() {
      getNews(this.$route.query.id).then(response => {
        this.news = response.data;
      });
    },
    goBack() {
      this.$router.push('/news2');
    },
    goHome() {
      this.$router.push('/userHome');
    }
  }
}
</script>

<style lang="scss" scoped>
.news-detail-container {
  max-width: 800px;
  margin: 30px auto;
  padding: 40px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 20px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.8);
  animation: fadeIn 0.6s ease-out;

  .news-header {
    margin-bottom: 40px;
    text-align: center;
    position: relative;
    padding-bottom: 30px;

    &::after {
      content: '';
      position: absolute;
      bottom: 0;
      left: 50%;
      transform: translateX(-50%);
      width: 60px;
      height: 3px;
      background: linear-gradient(90deg, #e61e1e, #ff6b6b);
      border-radius: 3px;
    }

    .news-title {
      font-size: 32px;
      color: #2c3e50;
      margin-bottom: 20px;
      font-weight: 600;
      line-height: 1.4;
      text-shadow: 0 2px 4px rgba(0,0,0,0.05);
    }

    .news-meta {
      color: #909399;
      font-size: 15px;
      display: flex;
      justify-content: center;
      align-items: center;
      gap: 20px;

      .time {
        display: flex;
        align-items: center;
        gap: 6px;
        
        &::before {
          content: '\e78f';
          font-family: element-icons;
          font-size: 16px;
        }
      }
    }
  }

  .news-content {
    line-height: 1.8;
    color: #2c3e50;
    font-size: 16px;
    padding: 30px 0;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);

    :deep(p) {
      margin-bottom: 20px;
      text-align: justify;
    }

    :deep(img) {
      max-width: 100%;
      border-radius: 12px;
      margin: 20px 0;
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
      transition: transform 0.3s ease;

      &:hover {
        transform: scale(1.02);
      }
    }

    :deep(h1), :deep(h2), :deep(h3) {
      color: #2c3e50;
      margin: 30px 0 15px;
      font-weight: 600;
    }

    :deep(blockquote) {
      border-left: 4px solid #e61e1e;
      padding: 15px 20px;
      background: rgba(230, 30, 30, 0.05);
      border-radius: 0 8px 8px 0;
      margin: 20px 0;
    }

    :deep(code) {
      background: #f8f9fa;
      padding: 2px 6px;
      border-radius: 4px;
      color: #e61e1e;
      font-family: monospace;
    }
  }

  .news-footer {
    margin-top: 40px;
    text-align: center;
    display: flex;
    justify-content: center;
    gap: 15px;
    
    .el-button {
      padding: 12px 30px;
      font-size: 15px;
      border-radius: 8px;
      transition: all 0.3s ease;

      &:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
      }
    }
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
</style>